﻿using System;
using System.IO;
using System.Configuration;
using System.Windows;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Collections.Generic;

namespace PIBV
{
    public class PDFQuadArgs : EventArgs
    {
        public Point size;
        public Point p1;
        public Point p2;
        public Point p3;
        public Point p4;
        public string Text;

        public PDFQuadArgs(Point psize, Point pp1, Point pp2, Point pp3, Point pp4, string text)
        {
            size = psize;
            p1 = pp1;
            p2 = pp2;
            p3 = pp3;
            p4 = pp4;
            Text = text;
        }

    }

    public class LoadDrawingEventArgs : EventArgs
    {
        public System.Windows.Point Position;
        public String DrawingFileName;
        public String PdfDrawingFileName;
        public String DgnDrawingFileName;
        public String LoopID;
        public String PID;

        public string FormName;
        public object Tag;

        public LoadDrawingEventArgs(Point pos, String fileName, String pdfFileName, String dgnFileName, String loopId, String pid)
        {
            Position = pos;
            DrawingFileName = fileName;
            LoopID = loopId;
            PdfDrawingFileName = pdfFileName;
            DgnDrawingFileName = dgnFileName;
            PID = pid;
        }
    }

    public static class PIDStringExtensions
    {
        public static string ChangeExtensionToPDF(this string s)
        {
            return s.Replace(".dgn", ".pdf").Replace(".dwg", ".pdf").Replace(".DGN", ".pdf").Replace(".DWG", ".pdf");
        }

        public static string[] SplitSasTag(this string s)
        {
            string[] result = null;
            List<string> res = new List<string>();

            if (s.Contains("-"))
            {
                result = s.Split('-');
            }
            else
            {
                int pos_prev = 0;
                int pos = 0;
                bool pred1 = char.IsDigit(s[0]);
                foreach (char c in s)
                {
                    bool pred2 = char.IsDigit(s[pos]);
                    if (pred2 != pred1)
                    {
                        //split at this place
                        string substr = s.Substring(pos_prev, pos - pos_prev);
                        pos_prev = pos;
                        res.Add(substr);
                    }

                    pred1 = pred2;

                    pos++;
                }

                string substr2 = s.Substring(pos_prev, pos - pos_prev);
                res.Add(substr2);

                result = res.ToArray();
            }

            return result;
        }

    }
    
}